home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / misc / avmNfax1_33.lha / avmsuite / AGMSRecordSound.doc < prev    next >
Text File  |  1994-04-23  |  19KB  |  403 lines

  1.                          AGMSRecordSound
  2.  
  3. AGMSRecordSound is a Modula-2 program by Alexander G. M. Smith which
  4. records sound samples to disk, using a standard parallel port audio
  5. digitizer.  AGMSRecordSoundPS3 is a modified version that works with
  6. version 3.0+ PerfectSound hardware.
  7.  
  8. To get you started, try this command:
  9.  
  10.   AGMSRecordSound ram:test verbose
  11.  
  12. Type a control-C to stop it.  You can play the resulting file with
  13. AGMSPlaySound or some other sound player.
  14.  
  15.  
  16. Propoganda
  17.  
  18. Since AGMSRecordSound doesn't need to fit the whole sample into one
  19. contiguous memory block, you can record samples longer than your memory
  20. size (up to 2 gigabytes).  It also multi-tasks so you can see the screen
  21. and do other things while recording, unlike all other sound digitizer
  22. programs I know of.
  23.  
  24.  
  25. Anti-propoganda
  26.  
  27. The downside of this is crummy audio quality.  Other digitizers take
  28. over the computer while recording since that is the best way to get
  29. better quality.  The trouble comes from code that temporarily disables
  30. interrupts, making AGMSRecordSound's interrupt routine miss a sound
  31. sample.  This happens all time time - whenever memory is allocated or
  32. deallocated, interrupts are disabled to prevent other programs from
  33. interfering.  Hopefully Commodore will put in some DMA circuits for
  34. digitizing so that we can get good quality and multitasking.
  35.  
  36.  
  37. Requirements
  38.  
  39. AGMSRecordSound requires sound sampler hardware plugged into the
  40. parallel port.  I've tested it with AMAS (records from the right
  41. channel) and it should work with most other parallel port digitizers
  42. (try left if right doesn't work).  If you have SunRize Industries'
  43. PerfectSound 3 digitizer then you have to use a different version of
  44. this program: AGMSPlaySoundPS3.  You also need to have the arp.library
  45. file (version 39 or 1.3) in your LIBS: directory.  If you have ARexx
  46. installed, AGMSRecordSound will take advantage of it.  Other than that, it
  47. should work on all Amigas.
  48.  
  49.  
  50. How It Works
  51.  
  52. An interrupt routine is set up for audio channel 1 (right side) that
  53. samples the parallel port, copies the data to the audio register and
  54. copies it to a buffer in memory.  Every time audio channel 1 needs a new
  55. sound sample, this interrupt routine is called.  When a buffer becomes
  56. full, it moves to the next buffer and signals the main program.  If
  57. there are no empty buffers to be filled, the interrupt routine will slow
  58. down the audio channel to a lower sampling rate (around 440 Hz) so that
  59. the processor will have more CPU time for running tasks (less used by
  60. the interrupt code).  You can still hear the sounds but they won't be
  61. stored in the buffer (not recorded in other words) and they will sound
  62. strange (like a dog growling under water) due to the lower sampling
  63. rate.  When an empty buffer becomes available, it will resume filling at
  64. normal speed.
  65.  
  66. The other half of AGMSRecordSound is a process that dumps filled buffers
  67. to a disk file.  If it is faster at emptying buffers than the interrupt
  68. routine is at filling them, it will go to sleep and wait for a signal:
  69. control-C (a signal from the user to stop recording) and control-F (a
  70. signal from the interrupt routine that another buffer is full).  In the
  71. PerfectSound version, it also responds to control-E (steps up the volume
  72. control).  After dumping each buffer, it can optionally test for a
  73. couple of stop conditions: reaching the maximum number of bytes or the
  74. sound being quiet for a long enough time.
  75.  
  76.  
  77. Sound Quality
  78.  
  79. The problems with disabled interrupts cause pops and similar noises -
  80. great if you are trying to simulate an old scratchy record (or to record
  81. one), but otherwise annoying.  The trick for getting "good" sound
  82. quality is to set the sampling rate to minimize this problem.
  83.  
  84. A really low sampling rate means that the disabled interrupt won't last
  85. long enough to cause trouble.  After interrupts are re-enabled, the
  86. pending audio interrupt will get through and the sample will only be
  87. delayed in time for a short while.  Samples after the delayed one will
  88. be back on schedule.  Unfortunately, most people don't like to record at
  89. 1kHz :-).  However, if you have a faster computer (I only have an A2000)
  90. then the disabled times will be shorter and sound quality should go up.
  91.  
  92. A really high sampling rate will suck up so much CPU time that only the
  93. interrupt routine will be running; every time it finishes sampling,
  94. another interrupt comes in.  This is actually quite useful (more later).
  95. You can tell that this is happening by the lack of mouse pointer
  96. movement when you move the mouse.  However, as soon as all the buffers
  97. are full, the interrupt routine will go into idle mode.  This frees up
  98. CPU cycles for running other tasks - like the mouse pointer movement and
  99. buffer saving.  As soon as one buffer has been saved, the interrupt
  100. routine will pick up speed and things will be frozen.
  101.  
  102. At high sampling rates, no other task is running and disabling
  103. interrupts.  This means high quality sound, almost as good as those
  104. dedicated non-multitasking sampler programs.  The catch is that nothing
  105. is recorded while the buffer is being dumped to disk.  So, if you can
  106. put up with brief pauses then you can use this mode.
  107.  
  108. Also, you can use AGMSRecordSound as an ordinary sound digitizer.  Just
  109. set the buffer size to fill up your whole memory (many smaller buffers
  110. are preferable since the interrupt routine can fill all but the one
  111. buffer being emptied - try buffers 20 size 100000 if you want to fill up
  112. 2 meg of memory).  Then set the sampling rate to one that uses all the
  113. CPU time for sampling (12kHz is good on my A2000, you will need larger
  114. rates on faster computers).
  115.  
  116. At ridiculously high sampling rates, the interrupt routine will be
  117. running flat out at a speed less than the one you requested.  This will
  118. result in a sample that is higher pitched than reality when you play it
  119. back.
  120.  
  121.  
  122. Embedded IFF Information
  123.  
  124. The output file is an IFF file.  You have lots of command line options
  125. available for specifying optional information (like sample name, author
  126. etc).  Unfortunately some other sound sample processing programs can't
  127. handle the extra info (but AGMSPlaySound can!).  If you find that you
  128. want to type in more information than will fit on a command line, put
  129. the long command line into a script file and execute it.
  130.  
  131.  
  132. Help
  133.  
  134. Most of the arguments to the program are obvious if you know audio
  135. terminology and computer terminology.  Anyways, you really don't have to
  136. specify any arguments except the name of the file to be created.  For
  137. on-line help, just type a ? as the argument to get the standard ARP /
  138. AmigaDOS command template.  A second ? typed at the template prompt will
  139. print the program credits.  The Verbose option also explains in more
  140. detail what the current settings are.  They are intuitively obvious
  141. (well, to me :-), but just in case you aren't intuitive about audio
  142. stuff, I'll describe the parameters in detail near the end of this
  143. message.
  144.  
  145.  
  146. Stolen Channels
  147.  
  148. This program won't let other programs steal its sound channel (channel 1
  149. to be specific).  It allocates it with maximum priority and thus hangs
  150. on to it.  If you are using AGMSPlaySound at the same time as you are
  151. recording, AGMSPlaySound will be bumped off channel 1 and will reappear
  152. on whatever other channel is free.  If someone else has channel 1 with
  153. the highest priority then AGMSRecordSound won't try recording.
  154.  
  155.  
  156. Error Handling
  157.  
  158. The main source of errors is from the file system.  In particular, you
  159. may encounter a disk full error once in a while :-).  When an error
  160. occurs, AGMSRecordSound stops whatever it is doing and shuts down.  It
  161. will return a return code of 10 when something goes wrong.
  162.  
  163. Now, more about those disk full errors.  I've set things up so that the
  164. file you are recording to is closed as if you had normally ended
  165. recording.  Since it is an IFF file, this means going back and filling
  166. in the size of the sample in previously written data near the beginning
  167. of the file.  It seems to work when using the old file system (OFS) but
  168. doesn't work under the fast file system (FFS).  Well, I tried.
  169.  
  170.  
  171. Technical Notes
  172.  
  173. Well, I found out a bit while writing this program.  Ok, two bits, make
  174. that three or four after I figured out the PS3 hardware :-).  For one
  175. thing, I found out how to use a digitizer: set CIAA port B to be all
  176. inputs (the parallel port).  Set CIAB port A pins POUT and SEL to be
  177. outputs.  The sampler spews out bytes to the parallel port with no
  178. handshaking, at some rate that I assume is pretty fast.  Some digitizers
  179. use a high level on SEL to connect the right audio input to the sampler
  180. and a high level on POUT to connect the left channel.  AMAS just
  181. seems to use the POUT bit to select left or right and seems to use right
  182. instead of left.  Whatever.  Once you have the desired channel, you can
  183. get a sample byte by reading the parallel port byte.  Subtract $80 from
  184. it to make it into a signed number and store it away.  Allow a small
  185. amount of time between switching from left to right (or vice versa) to
  186. let the sampler update its value (the time for a few instructions should
  187. be enough).
  188.  
  189. The PerfectSound 3.0+ hardware is a different story.  The sample byte is
  190. split between the parallel port (CIAA port B) and the miscellaneous bits
  191. port (CIAB port A).  The low 6 bits of parallel data (PB5-PB0 in CIAA)
  192. are actually the high six bits of the sample (shift them left by two).
  193. The low two bits of the sample are in the printer POUT (paper out) and
  194. BUSY signals (PA1-PA0 in CIAB).  As before, SEL (PA2 in CIAB) controls
  195. the left / right (zero is left).  So, what do PB6 and PB7 in CIAA do? A
  196. lot! The PerfectSound digitizer has a latched output, PB6 triggers the
  197. latch.  Set PB6 to zero to latch a value, read the sample, and set PB6
  198. back to one to start digitizing the next sample (I assume that's what
  199. it's doing).  PB7 is the gain control.  Normally you run the hardware
  200. with PB7 set to one.  If you toggle PB7 to zero and back, the volume
  201. control will be stepped up or down one notch of 16 levels.  SEL controls
  202. the volume direction (as well as left/right), zero for decreasing the
  203. volume.  The volume gain control wraps around from minimum to maximum
  204. and as far as I could tell, there isn't any way of telling what the
  205. current gain setting is or of setting it to minimum or maximum.
  206.  
  207. I experimented a bit with ways of generating interrupts before I clued
  208. in that no interrupts happen while interrupts are disabled.  CIA timers
  209. running continously are good.  Audio channels themselves are also good
  210. for making a periodic interrupt (and at exactly the same speed as
  211. playback too).  I even tried using an audio channel to generate an
  212. interrupt slightly before the audio channel I was using for timing would
  213. signal the next time period.  The early interrupt routine would then
  214. busy wait for the timing channel interrupt.  The "slightly" grew to over
  215. 800 CPU clock cycles before I got slightly improved sound (hey - a way
  216. of determining how long those disabled times are), slightly improved at
  217. a very slow sampling rate that made it useless.
  218.  
  219.  
  220. Feedback
  221.  
  222. If you have any feature requests or find any bugs, please send me a
  223. message.  I'm on several of the Ottawa BBX's (a BBS written by SteveX)
  224. and my commercial info service names are listed in the program's second
  225. help message (agmsmith@BIX.com and 71330.3173@CompuServe.com).
  226.  
  227.  
  228. Distribution
  229.  
  230. AGMSRecordSound is FreeWare.  Copyright (c) 1993 by Alexander G. M. Smith.
  231. That means that you can use it freely, can't blame me for anything that goes
  232. wrong (there are probably a few bugs left), and you shouldn't expect more
  233. from it than you paid for it.  Also, don't blame me if your hard drive fills
  234. up and then has problems with invalid directory structures - it happens to
  235. me too.
  236.  
  237.  
  238. File/A
  239.  
  240. Names the file where the sample will be stored.  Any existing file by
  241. this name will be erased.  A required keyword.  You can specify NIL: if
  242. you just want to monitor your digitizer without recording the sound to a
  243. file.  Only works in versions of AmigaDOS that support NIL:.
  244.  
  245.  
  246. Verbose/S
  247.  
  248. When this command switch is used, lots of interesting messages will be
  249. displayed.  All the parameter settings will be shown.  During recording
  250. you can see what buffers are being dumped.
  251.  
  252.  
  253. Buffers/K
  254.  
  255. This parameter specifies the number of buffers (any old ram is used) to
  256. use for recording the sound.  You need at least 2.  While the system is
  257. recording one buffer, the others can be emptied to disk.  Try the
  258. verbose command switch to watch the buffers being emptied and to see how
  259. changing the number of buffers affects performance.  Gee, I sure like
  260. these reuseable documentation paragraphs - I just changed "play" to
  261. "record" :-)
  262.  
  263.  
  264. BufferSize/K
  265.  
  266. This parameter sets the size of each sound buffer.  The default is
  267. 100000 bytes, the maximum is about 2000000000 bytes :-).  As mentioned
  268. elsewhere, AGMSRecordSound doesn't need to use any chip ram at all.
  269. Buffers use general purpose ram.  For best performance, use large
  270. buffers.  That is because DOS can write a large chunk of data faster
  271. than several small chunks (less overhead).
  272.  
  273.  
  274. Hz/K
  275.  
  276. This parameter controls the record rate.  It is in units of samples per
  277. second, or bytes per second since each sample is one byte long (compact
  278. disks have 2 byte samples and thus sound better).  The default is 7781
  279. hz, less for the PerfectSound version due to extra overhead in reading
  280. each sample.  The highest rate on my A2000 that lets you record and
  281. simultaneously save to disk (no gaps) is about 8500 hz.  A speed of
  282. 12000 hz is good for better quality sound with small gaps between
  283. buffers.  See the discussion on sound quality about picking values for
  284. hz.
  285.  
  286. The Hz setting is internally translated into a code value for the
  287. hardware.  Since the hardware doesn't have all that many code values,
  288. only a few frequencies are actually available.  A frequency near the one
  289. you specified will be picked.  Note that this is half the playback code
  290. value since playback plays words (pairs of bytes) while we only record a
  291. byte at a time.
  292.  
  293.  
  294. StopSize/K
  295.  
  296. This parameter specifies the maximum size of the sound sample file.  The
  297. default is two billion.  When this many bytes of data have been written,
  298. the sampling process will be stopped.  Because the interrupt routine may
  299. have filled up a few buffers before this much data has been written, you
  300. will get a bit more than the stop size in your file.
  301.  
  302.  
  303. StopQuiet/S
  304.  
  305. This switch triggers a neat feature requested by Hans Kerkhof who wanted
  306. something to record people calling in to a TV show.  If you specify
  307. StopQuiet then the sampling will also stop when the input is quiet for a
  308. long enough period of time.  This could also be useful for those of you
  309. making telephone answering machines.  The next few command line
  310. arguments control the definition of "quiet" and how much quiet is
  311. needed.
  312.  
  313.  
  314. QuietTime/K
  315.  
  316. This parameter lets you specify the integer number of seconds of quiet
  317. that will make the program stop recording.  The number is approximate
  318. and will be converted into a count of quiet sound sample buffers (see
  319. BufferSize) that would cover roughly the time you request.  The minimum
  320. time possible is the time it takes to record one sound sample buffer.
  321. If you specify the Verbose option, you can see the quiet time shown as
  322. the number of quiet buffers and the amount of real time that corresponds
  323. to.  The default value is zero (that becomes the time it takes to record
  324. one buffer).  Note that QuietTime is spelt with two "t"s in the middle,
  325. I often misspell it and get the error "Bad positional argument."
  326.  
  327.  
  328. QuietVolume/K
  329.  
  330. If you have StopQuiet turned on, then each buffer will be examined after
  331. it has been dumped to determine if it is "quiet".  A number of samples
  332. (adding up to 32 per second) will be picked out from the buffer and
  333. averaged together (or rather, the absolute value of each picked out
  334. sample will be averaged).  The resulting value, from 0 to 127, is a
  335. statistical estimate volume level of that buffer.  If you turn on the
  336. verbose option, it will show the buffer volume estimates.  If the volume
  337. is less than or equal to the QuietVolume you specify then that buffer
  338. counts as being "quiet".  If you get a certain number (determined by
  339. QuietTime) of quiet buffers in a row, then the program will stop.
  340.  
  341.  
  342. Name/K
  343.  
  344. This lets you specify the name of the song or whatever you have
  345. recorded.  If it is more than one word, put it in double quotes.
  346.  
  347.  
  348. Copyright/K
  349.  
  350. This is for the IFF copyright notice inside your sound sample.  Specify
  351. something like "1991, Alexander G. M. Smith".
  352.  
  353.  
  354. Author/K
  355.  
  356. The author of this sample.  If it is music then that is relatively
  357. obvious.  I don't know who is the author of the sound of a toilet
  358. flushing, maybe the toilet manufacturer?  Don't specify it if you don't
  359. want an author.
  360.  
  361.  
  362. Anno=Annotation/...
  363.  
  364. An endless list of annotation.  You can use the short form of the
  365. keyword (Anno) or the long form (Annotation).  The values are strings
  366. (as many as you want) of annotation text.  It can be whatever you want,
  367. usually something that describes the sample: anno "This is my first hour
  368. long sound sample" "The sound of the dripping tap was created by using
  369. the kitchen sink." "Use at your own risk."
  370.  
  371.  
  372. ARexx: StopRecording
  373.  
  374. If you have ARexx installed, AGMSRecordSound will open an ARexx port
  375. called "AGMSRecordSound" (note the case of the letters) and respond to
  376. commands.  Currently, the only command is "StopRecording" which will
  377. stop the recording, much like a Control-C does.  Have a look at the
  378. Test.rexx script included with the archive to see how to use
  379. AGMSRecordSound from ARexx.  You can thank Al Villarica for requesting
  380. this feature.
  381.  
  382.  
  383. Control-C Etc.
  384.  
  385. Control-C will abort the program as soon as possible.  This can take a
  386. while if it is busy dumping a buffer.
  387.  
  388. Control-E will step up the volume on the PerfectSound hardware, if you
  389. are using AGMSRecordSoundPS3 (does nothing otherwise).  Don't hit the
  390. key too fast, when AGMSRecordSoundPS3 is running the rest of the
  391. operating system is slowed down and can't process your signals fast
  392. enough.  In fact, it's so slow that you can overflow something (probably
  393. the supervisor stack) by typing a lot of Control-CDEF's, even in another
  394. program's window.  The result is a visit from the guru (crash #3
  395. usually).
  396.  
  397. Control-F is used by the interrupt routine to tell the main program that
  398. there is another full buffer.  You can use it to if you want to wake up
  399. a poor little sleepy program (doesn't do any harm, unless you type it
  400. too quickly :-).
  401.  
  402. - Alex
  403.